#!/usr/bin/env ruby

#make your own child class of AmaroKSlots to send to AmaroKLib.
module AmaroKSlots
	def AmaroKSlots.configure
		msg  = '"This script does not have configuration options."'
        	`dcop amarok playlist popupMessage "#{msg}"`
	end
	def AmaroKSlots.stateChange_empty
		nil
	end	
	def AmaroKSlots.stateChange_idle
		nil
	end
	def AmaroKSlots.stateChange_paused
		nil
	end
	def AmaroKSlots.stateChange_playing
		nil
	end
	def AmaroKSlots.trackChange
		`dcop amarok playlist popupMessage "track changed"`
	end
	#not a command given by amaroK, used when debugging
	def exit
		nil
	end
end


	loop do
		
    		message = gets().chomp() #Read message from stdin
    		line = /[A-Za-z]*/.match( message ).to_s()
		
		`dcop amarok playlist popupMessage "#{line}"`			#Pop up a window in amarok so I know what got scanned
		
		case line
			when 'configure' then AmaroKSlots.configure
			when 'trackChange' then AmaroKSlots.trackChange
			when 'engineStateChange: empty' then AmaroKSlots.stateChange_empty
			when 'engineStateChange: idle' then AmaroKSlots.stateChange_idle
			when 'engineStateChange: paused' then AmaroKSlots.stateChange_paused
			when 'engineStateChange: playing' then AmaroKSlots.stateChange_playing
			#not a command given by amaroK, helpful when debugging
			when 'exit' then AmaroKSlots.exit
			else $stderr.print "Illegal command: #{line}"
		end	
    	end